import { LOGIN_URL } from "@/config/config";
import { useRoute, useRouter } from "vue-router";
import { AuthStore } from "@/stores/modules/auth";
import { getDefaultMenu } from "@/hooks/useSystem";
// const projectInfo = "宏电大厦配电房组态";
export const useTopo = () => {
	const router = useRouter();
	const route = useRoute();
	const isFullscreen = ref();

	const toggelFullscreen = (param?: { init?: boolean }) => {
		// 全屏
		const element: any = document.documentElement;
		if (!(param?.init == true) && document.fullscreenElement) {
			document.exitFullscreen();
			isFullscreen.value = false;
		} else {
			if (element.requestFullscreen) {
				element.requestFullscreen();
			} else if (element.msRequestFullscreen) {
				element.msRequestFullscreen();
			} else if (element.mozRequestFullScreen) {
				element.mozRequestFullScreen();
			} else if (element.webkitRequestFullscreen) {
				element.webkitRequestFullscreen();
			}
			isFullscreen.value = true;
		}
	};
	const gotoExit = () => {
		if (document.fullscreenElement) {
			document.exitFullscreen();
			isFullscreen.value = false;
		}
		let menu = AuthStore().authMenuList?.find(item => item.path == "/data/monitor") || getDefaultMenu(route.path);
		if (menu?.path && menu.path != route.path) {
			router.push({ path: menu.path });
		} else {
			router.push({ path: menu?.path || LOGIN_URL, query: { type: "logout" } });
		}
	};
	return { gotoExit, toggelFullscreen, isFullscreen };
};
